<?php
final class XClassRegistry{
	private static $instance = null;
	private $entities = array();
	private $controllers = array();
	private $services = array();
	private static $TYPES = array(
		'Aspect',
		'Controller',
		'Entity',
		'Service',
		'EventListener',
		'EventPublisher',
	);
	
	private function __construct() {
	
	}
	
	/** 
	 * @return XClassRegistry
	 */	
	static function singleton() {
		if (!self::$instance) {
			self::$instance = new self;
		}
		return self::$instance;
	}
	
	public function entities(){
		return $this->entities;
	}
	
	/** 
	 * @return XClassRegistry
	 */	
	public function addEntity($class){
		$this->entities[$class] = $class;
		return $this;
	}
		
	public function controllers(){
		return $this->controllers;
	}
	
	/** 
	 * @return XClassRegistry
	 */	
	public function addController($class){
		$this->controllers[$class] = $class;
		return $this;
	}
	
	public function services(){
		return $this->services;
	}
	
	/** 
	 * @return XClassRegistry
	 */	
	public function addService($class){
		$this->services[$class] = $class;
		return $this;
	}
	
	/**
	 * @return XClassRegistry
	 */	
	public function register($type, $class, $params = array()){
		switch(strtolower($type)){
			case 'aspect':
				XAnnotationAOPRegister::singleton()->register($class);
				return $this;
			case 'controller':
				return $this->addController($class);
			case 'entity':
				return $this->addEntity($class);
			case 'service':
				return $this->addService($class);	
			case 'eventlistener':
				if(XClassLoader::loader($class)->implementsInterface('XEventListener')){
					$listener = XFactory::singleton()->get($class);
					XEventContext::singleton()->addListenerByParams($listener, $params);
				}
				return $this;
			case 'eventpublisher':
				//TODO	
				return $this;		
		}
		return $this;
	}
			
	public static function types(){
		return self::$TYPES;
	}
	
}
?>